﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Engine.Sgml.Schema;

namespace Engine.Sgml.Test.Util {
    public class DModelGroupsConfiguration {
        private Random random = new Random(0);

        public DModelGroupsConfiguration(DElementConfiguration elementConfig) {
            ElementConfiguration = elementConfig;
            Occurrance = DElementOccurrence.OnlyOnce;
            OrderType = DGroupOrderType.OnlyOne;
            MaxDepth = 3;
            MaxLength = 5;
            MaxDistanceBetweenInnerGroups = 3;
            }

        public DModelGroupsConfiguration Random() {
            DModelGroupsConfiguration result = new DModelGroupsConfiguration(ElementConfiguration);
            result.OrderType = (DGroupOrderType)random.Next(3);
            result.Occurrance = (DElementOccurrence)random.Next(4);
            result.MaxLength = MaxLength;
            result.Depth = Depth - 1;
            return result;
            }

        public DElementConfiguration ElementConfiguration { get; private set; }
        public DElementOccurrence Occurrance { get; set; }
        public DGroupOrderType OrderType { get; set; }
        public int MaxDistanceBetweenInnerGroups { get; set; }
        public bool GenerateInclusionElements { get; set; }

        public int InclusionElementCount {
            get { return random.Next(1, maxLength + 1); }
            }


        private int maxDepth;
        public int MaxDepth {
            get { return maxDepth; }
            set {
                maxDepth = value;
                Depth = random.Next(1, maxDepth + 1);
                }
            }

        private int maxLength;
        public int MaxLength {
            get { return maxLength; }
            set {
                maxLength = value;
                Length = random.Next(1, maxLength + 1);
                }
            }

        public int Length { get; private set; }

        public int Depth { get; private set; }

        public int DistanceBetweenInnerGroups {
            get { return random.Next(1, MaxDistanceBetweenInnerGroups); }
            }

        public bool GenerateElement {
            get {
                switch (random.Next(2)) {
                    case 0:
                        return true;
                    case 1:
                        return false;
                    default:
                        throw new InvalidOperationException();
                    }
                }
            }
        }
    }
